package com.example.message;

import com.example.entity.User;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {
    
    @RabbitListener(queues = "simple")
    public void listen(String msg) {
        System.out.println(msg);
    }
    
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "boot_queue"),
            exchange = @Exchange(value = "boot_exchange", type = ExchangeTypes.DIRECT),
            key = "msg"
        )
    )
    public void createAndListen(Message msg) {
        System.out.println(msg.getBody());
        System.out.println(msg.getMessageProperties());
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "boot_queue"),
            exchange = @Exchange(value = "boot_exchange", type = ExchangeTypes.DIRECT),
            key = "user"
    )
    )
    public void createAndListen2(User msg) {
        System.out.println(msg);
    }
    
}




